#pragma once

#include <Magick++.h>

template <class CA, class Func>
Magick::Image renderCA(const CA & ca, Func func)
{
  int width = ca.getWidth(), height = ca.getHeight();
  
  Magick::Image img;
  img.size( Magick::Geometry(width, height) );
  img.modifyImage();
  Magick::PixelPacket *pixel_cache = img.getPixels(0, 0, width, height);
  
  for (int y = 0; y != height; ++y)
    for (int x = 0; x != width; ++x)
      *(pixel_cache + y * width + x) = func(ca, x, y);

  return img;
}
